import axios from './axios'

import {
    LOGIN,
    USERLIST,
    ADMINADD,
    USERSTATUS,
    USEREDit,
    USERDEL,

    AUTHEDIT,
    AUTHSTATUS,
    AUTHDEL, 
    AUTHADD, 
    AUTHLIST, 

    ROLELIST,
    ROLEADD,
    ROLE,
    ROLEEDIT,
    ROLEDEL,

    CATLIST,
    CATADD,
    CATEDIT,
    CATDEL,

    DISHLIST,
    DISHADD,
    DISHEDIT,
    DISHDEL
} from './url'

/*-------------- 角色相关 ---------------*/
// 角色列表
export function roleList() {
    return axios(ROLELIST)
}

// 角色添加
export function roleAdd(data) {
    return axios(ROLEADD, {
        method: 'post',
        data: {
            name: data.name,
            auths: data.auths.join(',')
        }
    })
}

// 获取一个角色
export function role(id) {
    return axios(ROLE + '/' + id)
}

// 角色修改
export function roleEdit(data) {
    return axios(ROLEEDIT + '/' + data.id, {
        method: 'put',
        data: {
            name: data.name,
            auths: data.auths.join(',')
        }
    })
}

// 角色删除
export function roleDel(id) {
    return axios.delete(ROLEDEL + '/' + id)
}

/*------------------- 用户相关 ---------------------*/
// 登录
export function adminLogin(data) {
    // console.log(data);
    return axios(LOGIN, {
        data,
        method: 'post'
    })
}

// 用户添加
export function adminAdd(data) {
    return axios(ADMINADD, {
        method: 'post',
        data
    })
}

// 修改用户启用状态
export function changeEnable(id) {
    return axios.put(USERSTATUS + '/' + id)
}

// 用户修改
export function userEdit(data) {
    return axios(USEREDit + '/' + data._id, {
        method: 'put',
        data: data
    })
}

// 用户删除
export function userDel(id) {
    return axios.delete(USERDEL + '/' + id)
}

// 用户列表
export function userList() {
    return axios(USERLIST)
}

/*---------------- 权限相关 ---------------*/
// 添加权限
export function authAdd(data) {
    return axios(AUTHADD, {
        method: 'post',
        data
    })
}

// 获取所有权限
export function authList() {
    return axios(AUTHLIST)
}

// 权限修改
export function authEdit(data) {
    // console.log(data); return
    return axios(AUTHEDIT + '/' + data._id, {
        method: 'put',
        data
    })
}

// 切换权限展示状态
export function changeShowStatus(id) {
    return axios.put(AUTHSTATUS + '/' + id,)
}

// 权限删除
export function authDel(id) {
    return axios.delete(AUTHDEL + '/' + id)
}

/*----------------- 分类 -------------------*/
export function catList() {
    return axios(CATLIST)
}

export function catAdd(data) {
    return axios(CATADD, {
        method: 'post',
        data
    })
}

export function catEdit(data) {
    return axios(CATEDIT + '/' + data.id, {
        method: 'put',
        data
    })
}

export function catDel(id) {
    return axios.delete(CATDEL + '/' + id)
}

/*---------------- 商品 ----------------*/
export function dishList() {
    return axios(DISHLIST)
}

export function dishAdd(data) {
    return axios(DISHADD, {
        method: 'post',
        data
    })
}

export function dishEdit(data) {
    return axios(DISHEDIT + '/' + data.id, {
        method: 'put',
        data
    })
}

export function dishDel(id) {
    return axios.delete(DISHDEL + '/' + id)
}